home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 151 / cd-rom 151.iso / internet / firefox / Firefox Setup 3.0 Beta 1.exe / optional / extensions / inspector@mozilla.org / components / inspector-cmdline.js
Encoding:
Text File  |  2007-11-09  |  6.4 KB  |  180 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is DOM Inspector.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Christopher A. Aillon <christopher@aillon.com>.
  18.  * Portions created by the Initial Developer are Copyright (C) 2003
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Christopher A. Aillon <christopher@aillon.com>
  23.  *
  24.  * Alternatively, the contents of this file may be used under the terms of
  25.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  26.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27.  * in which case the provisions of the GPL or the LGPL are applicable instead
  28.  * of those above. If you wish to allow use of your version of this file only
  29.  * under the terms of either the GPL or the LGPL, and not to allow others to
  30.  * use your version of this file under the terms of the MPL, indicate your
  31.  * decision by deleting the provisions above and replace them with the notice
  32.  * and other provisions required by the GPL or the LGPL. If you do not delete
  33.  * the provisions above, a recipient may use your version of this file under
  34.  * the terms of any one of the MPL, the GPL or the LGPL.
  35.  *
  36.  * ***** END LICENSE BLOCK ***** */
  37.  
  38. // NOTE: this file implements both the seamonkey nsICmdLineHandler and
  39. // the toolkit nsICommandLineHandler, using runtime detection.
  40.  
  41. const INSPECTOR_CMDLINE_CONTRACTID = "@mozilla.org/commandlinehandler/general-startup;1?type=inspector";
  42. const INSPECTOR_CMDLINE_CLSID      = Components.ID('{38293526-6b13-4d4f-a075-71939435b408}');
  43. const CATMAN_CONTRACTID            = "@mozilla.org/categorymanager;1";
  44. const nsISupports                  = Components.interfaces.nsISupports;
  45.  
  46. const nsICategoryManager           = Components.interfaces.nsICategoryManager;
  47. const nsICmdLineHandler            = Components.interfaces.nsICmdLineHandler;
  48. const nsICommandLine               = Components.interfaces.nsICommandLine;
  49. const nsICommandLineHandler        = Components.interfaces.nsICommandLineHandler;
  50. const nsIComponentRegistrar        = Components.interfaces.nsIComponentRegistrar;
  51. const nsISupportsString            = Components.interfaces.nsISupportsString;
  52. const nsIWindowWatcher             = Components.interfaces.nsIWindowWatcher;
  53.  
  54. function InspectorCmdLineHandler() {}
  55. InspectorCmdLineHandler.prototype =
  56. {
  57.   /* nsISupports */
  58.   QueryInterface : function handler_QI(iid) {
  59.     if (iid.equals(nsISupports))
  60.       return this;
  61.  
  62.     if (nsICmdLineHandler && iid.equals(nsICmdLineHandler))
  63.       return this;
  64.  
  65.     if (nsICommandLineHandler && iid.equals(nsICommandLineHandler))
  66.       return this;
  67.  
  68.     throw Components.results.NS_ERROR_NO_INTERFACE;
  69.   },
  70.  
  71.   /* nsICmdLineHandler */
  72.   commandLineArgument : "-inspector",
  73.   prefNameForStartup : "general.startup.inspector",
  74.   chromeUrlForTask : "chrome://inspector/content/inspector.xul",
  75.   helpText : "Start with the DOM Inspector.",
  76.   handlesArgs : true,
  77.   defaultArgs : "",
  78.   openWindowWithArgs : true,
  79.  
  80.   /* nsICommandLineHandler */
  81.   handle : function handler_handle(cmdLine) {
  82.     var args = Components.classes["@mozilla.org/supports-string;1"]
  83.                          .createInstance(nsISupportsString);
  84.     try {
  85.       var uristr = cmdLine.handleFlagWithParam("inspector", false);
  86.       if (uristr == null)
  87.         return;
  88.       try {
  89.         args.data = cmdLine.resolveURI(uristr).spec;
  90.       }
  91.       catch (e) {
  92.         return;
  93.       }
  94.     }
  95.     catch (e) {
  96.       cmdLine.handleFlag("inspector", true);
  97.     }
  98.  
  99.     var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
  100.                            .getService(nsIWindowWatcher);
  101.     wwatch.openWindow(null, "chrome://inspector/content/", "_blank",
  102.                       "chrome,dialog=no,all", args);
  103.     cmdLine.preventDefault = true;
  104.   },
  105.  
  106.   helpInfo : "  -inspector <url>     Open the DOM inspector.\n"
  107. };
  108.  
  109.  
  110. var InspectorCmdLineFactory =
  111. {
  112.   createInstance : function(outer, iid)
  113.   {
  114.     if (outer != null) {
  115.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  116.     }
  117.  
  118.     return new InspectorCmdLineHandler().QueryInterface(iid);
  119.   }
  120. };
  121.  
  122.  
  123. var InspectorCmdLineModule =
  124. {
  125.   registerSelf : function(compMgr, fileSpec, location, type)
  126.   {
  127.     compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
  128.  
  129.     compMgr.registerFactoryLocation(INSPECTOR_CMDLINE_CLSID,
  130.                                     "DOM Inspector CommandLine Service",
  131.                                     INSPECTOR_CMDLINE_CONTRACTID,
  132.                                     fileSpec,
  133.                                     location,
  134.                                     type);
  135.  
  136.     var catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
  137.     catman.addCategoryEntry("command-line-argument-handlers",
  138.                             "inspector command line handler",
  139.                             INSPECTOR_CMDLINE_CONTRACTID, true, true);
  140.     catman.addCategoryEntry("command-line-handler",
  141.                             "m-inspector",
  142.                             INSPECTOR_CMDLINE_CONTRACTID, true, true);
  143.   },
  144.  
  145.   unregisterSelf : function(compMgr, fileSpec, location)
  146.   {
  147.     compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
  148.  
  149.     compMgr.unregisterFactoryLocation(INSPECTOR_CMDLINE_CLSID, fileSpec);
  150.     catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
  151.     catman.deleteCategoryEntry("command-line-argument-handlers",
  152.                                "inspector command line handler", true);
  153.     catman.deleteCategoryEntry("command-line-handler",
  154.                                "m-inspector", true);
  155.   },
  156.  
  157.   getClassObject : function(compMgr, cid, iid)
  158.   {
  159.     if (cid.equals(INSPECTOR_CMDLINE_CLSID)) {
  160.       return InspectorCmdLineFactory;
  161.     }
  162.  
  163.     if (!iid.equals(Components.interfaces.nsIFactory)) {
  164.       throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  165.     }
  166.  
  167.     throw Components.results.NS_ERROR_NO_INTERFACE;
  168.   },
  169.  
  170.   canUnload : function(compMgr)
  171.   {
  172.     return true;
  173.   }
  174. };
  175.  
  176.  
  177. function NSGetModule(compMgr, fileSpec) {
  178.   return InspectorCmdLineModule;
  179. }
  180.